<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>应用模块管理</title>
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<script type="text/javascript">

	function onLoad(){
		if(parseInt("${result}")>0){
			alert("删除成功");
		}else if(parseInt("${result}")<0){
			alert("删除失败");
		}
	}

	function rowClickAfter(rowIndex) {
		var  arrId = document.getElementsByName("check");
		arrId[rowIndex -1 ].checked = !arrId[rowIndex -1 ].checked;
	}

	function deleteModule(){
		var modules = getCheckedModule();
		if(modules==""){
			alert("请先选择一个要删除的模块！");
		}else{
			if(JLUtil.doConfirm("您真的确定要删除模块吗？")){
				ajaxRequest();
			}
		}
	}

	function generateModuleCode(){
		var modules = getCheckedModule();
		if(modules==""){
			alert("请先选择一个要生成代码的模块！");
		}else{
			if(JLUtil.doConfirm("确认生成模块的代码？")){
				JLAjax.ajaxJson("${ctx}/appFrameModule1/generateModuleCode",
						{'appId':'${appid}','modules':modules},generateModuleCodeBack);
			}
		}
	}

	// 执行生成模块代码后的回调函数
	function generateModuleCodeBack(data){
		alert(data.em);
	}

	// 获取选中的模块
  	function getCheckedModule(){
	    var str="";
	    var chkAll = document.getElementsByName("check");     
		for(var i=0;i<chkAll.length;i++){
		  if(chkAll[i].checked==true) 
			  str=str+chkAll[i].value+",";  
		}
		str=str.substring(0,str.length-1);
        return str;
 	 }
  
  
  	function ajaxRequest() {
		var modules = getCheckedModule();
	 	if(modules!=""){
	    	$.ajax({
		      url: "${ctx}/appFrameModule1/ajax?appid=${appid}&moduleid="+modules,
		      type: "POST",
		      dataType: "json",
		      async: false,
		      success: function(data) {
		        alert("删除成功！");
		       $.each(data, function(index, element) {
		           //window.location.reload(true);
		           window.parent.location.reload(true);
		        });
		      },
		      error: function() {
		        alert("error");
		      }
		    });
	 }else{
		 alert("请选择模块！");
	 }
  }

  function addModules(){
		window.location.href="${ctx}/appFrameModule/modulelist?update=1&appid=${appid}";
  }
  
  function createSubModule(){
	  var modules = getCheckedModule();
	  window.location.href="${ctx}/appFrameModule1/createSonModule?appid=${appid}&appname=${appname}&moduleid="+modules;
  }
</script>
</head>
<body onload="onLoad();">
<div class="panel panel-default">
   <div class="panel-heading">
      <h3 class="panel-title">
          APP模块信息
      </h3>
   </div>
   <div class="panel-body">
   		<form id="dataListForm" method="post"  action="${ctx}/appFrameModule1/appFrameModuleList1?appid=${appid}">
			<div class="ps-btn-opt">
			
				<input type="button" class="btn btn-default" value="创建下级模块"  onclick="createSubModule();"/> 
				<input type="button" class="btn btn-default" value="添加已存在模块"  onclick="addModules();"/> 
				<input type="button" class="btn btn-default" value="移除模块"  onclick="deleteModule();"/>
				<input type="button" class="btn btn-default" value="生成代码"  onclick="generateModuleCode();"/>  
				<a id="crt" href="${ctx}/make/main" target="_blank"/></a>
				<a id="mnt" href="${ctx}/monitor/main" target="_blank"/></a>
			</div>
			<br>		
			<table class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr class="active" align="center">
						<td>选择</td>
						<td>应用标识</td>
						<td>模块标识</td>
						<td>模块名称</td>
						<td>最近修改日期</td>
						<td>生成代码日期</td>
						<td>参数设置</td>
					</tr>
				</thead>				
				<tbody>
				<c:forEach items="${Modulelist}" var="module"  varStatus="s" >
				        <tr align="center" class="row_module" id="${module.moduleId}" >
				        	<td><input type="checkbox" name="check" id="check" value="${module['module_id']}"></input></td>
							<td>${module['app_id']}</td>
							<td>${module['module_id']}</td>
							<td>${module['module_name']}</td>
							<td>${module['last_modify_date']}</td>
							<td>${module['last_code_date']}</td>
 							<td><a id="mnt" href="/macms/appFrameModule/edit?appid=${module['app_id']}&moduleid=${module['module_id']}"/>模块设置</a></td> 
						</tr>  				
				</c:forEach>																
				</tbody>
			</table>
			<%@ include file="/page/page.jsp" %>
		</form>
    </div>
</div>
</body>
</html>
<script language="javascript">
	    var preRow = null;
		$('tbody tr').bind('click', function() {
	
			var rowIndex = $(this).prevAll().length+1;
			if(rowIndex <1) return;
			
			if(preRow != null){
				preRow.removeClass("active");
			}
			$(this).addClass("active");
			preRow = $(this);
			
			// 行单击后事件(传入行号，应用ID,应用名称信息)
			rowClickAfter(rowIndex);
		});
	</script>
